package com.mhwx.mhlive.util;

import android.app.Activity;
import android.content.Context;
import android.os.Handler.Callback;
import android.os.Message;
import android.widget.Toast;

import com.mhwx.mhlive.MyApplication;
import com.mhwx.mhlive.ui.widget.SharePopupWindow;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;


/**
 * Created by gujun on 2014/11/7.
 */
public class ShareSdkUtil {
    public static final int SHARE_VIDEO = 1;
    public static final int SHARE_IMAGE = 2;
    public static final int SHARE_CONTENT = 3;
    private static final int MSG_ACTION_CCALLBACK = 4;
    static int TYPE = 5;
    private static SharePopupWindow popupWindow;
    private static Context mContext;
    private static Callback callback = new Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.arg1) {
                case 1:
                    // 成功  用tostutil微信回调不起作用，所以改用tost
                    Toast.makeText(mContext, "分享成功", Toast.LENGTH_LONG).show();
                    break;
                case 2:
                    // 失败
                    Toast.makeText(mContext, "分享失败", Toast.LENGTH_LONG).show();
                    break;
                case 3:
                    // 取消
                    Toast.makeText(mContext, "取消分享", Toast.LENGTH_LONG).show();
                    break;
            }
            return false;
        }
    };

    public static void attentionWeibo(Activity context, String account, String platformName, UMShareListener paListener) {
        new ShareAction(context).setPlatform(SHARE_MEDIA.SINA)
                .setCallback(paListener)
                .withText(platformName).share();

    }


    //获取第三方平台用户资料
    public static void loginThirdPlatform(Activity context, SHARE_MEDIA mPlatform, UMAuthListener paListener) {
        mContext= MyApplication.getAppContext();
        boolean isauth=UMShareAPI.get(mContext).isAuthorize(context,mPlatform);
//        if (isauth) {
//            UMShareAPI.get(mContext).deleteOauth(context, mPlatform, paListener);
//        }
//        UMShareAPI.get(mContext).doOauthVerify(context,mPlatform,paListener);

        UMShareAPI.get(mContext).getPlatformInfo(context,mPlatform,paListener);//授权并获取用户资料
    }

    public static void selectSharePlatform(Activity a, int showAtLocationId, int type, String title, String content, String contentWb, String contentImage, String img, String targetUrl) {
        if (a == null) return;
        if (popupWindow != null) popupWindow.dismiss();
        popupWindow = new SharePopupWindow(a.findViewById(showAtLocationId), a, type, title, content, contentWb, contentImage, img, targetUrl);
    }

    public static void sharePlatform(Context context, String platformName, int type, String title, String content, String contentWb, String contentImage, String img, String targetUrl) {
        mContext = context;
        if (popupWindow != null) popupWindow.dismiss();
        TYPE = type;
        if (type == SHARE_VIDEO) {
            shareMediaVideo(context, platformName, title, content, contentWb, img, targetUrl);
        } else if (type == SHARE_IMAGE) {
            shareMediaImage(context, platformName, title, content, contentImage, img, targetUrl);
        } else if (type == SHARE_CONTENT) {
            shareMediaContent(context, platformName, title, content, contentWb, img, targetUrl);
        }
    }

    private static void shareMediaContent(final Context context, String platformName, String title, String content, String contentWeb, String img, String targetUrl) {

    }

    private static void shareMediaImage(final Context context, String platformName, String title, String content, String contentWb, String img, String targetUrl) {

    }

    private static void shareMediaVideo(Context context, String platformName, String title, String content, String contentWb, String img, String targetUrl) {


    }

//    private static void shareComplete(Activity a, String platformName) {
//        if (platformName.equals(SinaWeibo.NAME)) {
//            HttpRequest.appProbe(a, Probe.eventId_share, Probe.uri_share_sina);
//        } else if (platformName.equals(Wechat.NAME)) {
//            HttpRequest.appProbe(a, Probe.eventId_share, Probe.uri_share_weixin);
//        } else if (platformName.equals(WechatMoments.NAME)) {
//            HttpRequest.appProbe(a, Probe.eventId_share, Probe.uri_share_weixin_circle);
//        } else if (platformName.equals(QZone.NAME)) {
//            HttpRequest.appProbe(a, Probe.eventId_share, Probe.uri_share_qzone);
//        }
//    }

    private static void directShare(final Activity context, SHARE_MEDIA platformName) {

    }




}

